/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.product.web.ProductAction
   Module Description   :

   Date Created      : 2009/11/23
   Original Author   : ellen.li
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   TODO 1.HTMLeditor 
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.product.web;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.core.admin.entity.Group;
import com.yaodian100.core.admin.entity.Role;
import com.yaodian100.core.admin.entity.User;
import com.yaodian100.core.admin.entity.UserPermission;
import com.yaodian100.core.admin.entity.Permission.Type;
import com.yaodian100.core.admin.service.GroupService;
import com.yaodian100.core.admin.service.UserService;
import com.yaodian100.core.admin.utils.AdminHelper;
import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.core.common.entity.SimplePager;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.DomainService;
import com.yaodian100.core.common.utils.ServerValue;
import com.yaodian100.core.menu.entity.Menu;
import com.yaodian100.ec.category.entity.Category;
import com.yaodian100.ec.category.service.CategoryService;
import com.yaodian100.ec.common.EcConstant;
import com.yaodian100.ec.product.entity.AddOnProduct;
import com.yaodian100.ec.product.entity.Brand;
import com.yaodian100.ec.product.entity.Product;
import com.yaodian100.ec.product.entity.ProductCategory;
import com.yaodian100.ec.product.entity.ProductPromotionFlag;
import com.yaodian100.ec.product.entity.ProductSupplierApprove;
import com.yaodian100.ec.product.entity.Specification;
import com.yaodian100.ec.product.entity.SpecificationInventory;
import com.yaodian100.ec.product.service.ProductService;
import com.yaodian100.ec.product.service.ProductSupplierApproveService;
import com.yaodian100.ec.supplierapply.entity.SupplierApply;
import com.yaodian100.ec.supplierapply.service.SupplierApplyService;

/**
 * @author ellen.li
 * 
 */
public class ProductAction extends ActionSupport implements Preparable {

	/**
	 * serial version
	 */
	private static final long serialVersionUID = 817445883772265312L;
	private final Logger logger = LoggerFactory.getLogger(ProductAction.class);
	private ProductService productService;
	private CategoryService categoryService;
	private UserService userService;
	private GroupService groupService;
	private DomainService<Menu> menuService;
	@Resource
	private SupplierApplyService supplierApplyService;
	@Resource
	private ProductSupplierApproveService productSupplierApproveService;

	/* supplier */
	private Collection<SupplierApply> suppliers;// 己選的供應商
	private String[] supplierDelete;
	private List<Category> categoryRoot;
	private String showSelectedCategory;// 選取的目錄名稱
	private List<ProductCategory> selectedcategories;// 已选的目录
	private String setMainCategory;// 設為主目錄
	private String setMainSupplier;// 設為主供應商
	private String[] delSelectedCategory;// 刪除目錄
	private String mainCategoryName;
	private Product product;
	private List<Specification> specifications;
	private Specification specification;
	private String productId;
	private List<SpecificationInventory> specificationinventorys;
	private SpecificationInventory specificationinventory;
	private ProductPromotionFlag productPromotionFlag;
	private Map<String, String> fileMap;
	private List<Category> rootCategories;
	private Map<String, String> mapRootCategories;
	private String categoryResult;
	private String jsonCategoryPath;
	private Menu freightMenu;
	private Menu attributeMenu;
	private Menu specStatusMenu;
	private Menu specSubStatusMenu;
	private List<Group> groups;
	private String specStatusParam;
	private String brandName;
	private Menu expireManageMenu;
	private Map<Long, List<Integer>> specificationinventoryMap = new HashMap<Long, List<Integer>>();
	private SupplierApply sp;
	private String spResult = "false";
	private boolean chkHasInventory;
	/* 缺货报表參數 */
	private List<Object> stockReports;
	private String productStParam;
	private String categoryIdParam;
	private String pmIdParam;
	private String isPmGroup;
	private boolean stockNotify;
	private int startStockQty;
	private int endStockQty;
	private String[] productIdBoxs;
	private String arrivalDate;

	/* 分頁 */
	private SimplePager pager;
	private List<Product> products;
	private Map<String, String> rsmap = new HashMap<String, String>();
	private final String[] SORT_BY = new String[] { "productId desc" };

	/* 商品列表頁參數 */
	private String productNameParam;// 商品名称
	private String productIdParam;// 商品编号
	private String productTypeParam;// 商品型态
	private String categoryLevel1Param;// 馆别
	private String categoryLevel2Param;// 次分类
	private String productAttributeParam;// 销售状态
	private String supplierParam;// 供应商
	private String brandParam;// 品牌
	private String scmParam;// 转单状态

	/* 商品頁面參數 */
	private String name;
	private String type;
	private String virtual;
	private String cost;
	private String price;
	private String brief;
	private String description;
	private String details;
	private String brand;
	private String tax;
	private String editleadtime;
	private String delivertolerance;
	private String length;
	private String width;
	private String height;
	private String weight;
	private String volume;
	private String unit;
	private String minpo;
	private String maxpo;
	private String temperature;
	private String returnpickup;
	private String returnable;
	private String editsupplier;
	private String editTwSupplier;// 台湾馆供应商
	private String editbrand;
	private String pm;
	private String organization;
	private String memo;
	private String[] prdtDelete;
	private String keyword;
	private String editDeliverGeoRange;
	private List<Brand> brands;// 品牌
	private String showSeq;
	private Category category;
	private String orderNotice;
	private String jsonOrderNotice;
	private String expectShipDate;
	private String flag01;
	private String flag02;
	private String flag03;
	private String flag04;
	private String flag05;
	private String flag06;
	private String flag07;
	private String flag08;
	private String flag09;
	private String flag10;
	private String flag11;
	private String flag12;
	private String flag13;
	private String flag14;
	private String flag15;
	private String flag16;
	private String categoryPath;
	private String mainCategoryId;
	private List<User> users;
	private String productAttribute;
	private String supplierCompanyName;
	private String twSupplierCompanyName;
	private String isScm;
	private String scmNotice;
	private String hr24Result;
	private String expireManage;
	private String isAntiUnpacking;
	private String graphicType;
	private int approveSize = 0;
	private List<AddOnProduct> addonsMain = null;
	private List<AddOnProduct> addons = null;
	private List<AddOnProduct> nms = null;
	private String prpsShelfPrice;
	private String copy;
	private String isValidateNum = "N";
	private String useDeliveryDay = "N";
	private int deliveryDay = 0;

	/* Spec頁面參數 */
	private String[] spcName;
	private String[] spcId;
	private String[] spcCode;
	private String[] spcBarCode;
	private String[] spcReverseInventory;
	private String[] spcMaxCountPerOrder;
	private String[] spcMinCountPerOrder;
	private String[] spcSafeInventory;
	private String[] spcDelete;
	private String[] showSpecSeq;
	private String[] spcHotSaleInventory;
	private String[] specStatus;
	private int stockQty;
	private int totalInventory;
	private int totalHotSale;

	/* 商品目录页面参数 */
	private List<ProductCategory> productCategories;
	private Long mainCategory;
	private String lastMainCategoryId;
	private String mainCategoryText;
	private String editFlag;
	private Map<Long, String> productCategoryMap;
	private List<ProductCategory> editProductCategories;
	private String finalAddOnData;
	private String categoryId;
	private String jsonAddonProdSpec;
	private String userPermissions = "";

	DateFormat format = new SimpleDateFormat(EcConstant.PATTERN_DATE);

	private String specificId;
	List<Object> orderNoShippingList;
	private Menu orderStMenu;

	public String add() throws CoreException {
		product = new Product();
		product.setShowSeq(101);
		product.setIsScm("B");
		productId = "";
		setBrief("★&nbsp;\n★&nbsp;\n★&nbsp;\n★&nbsp;\n★&nbsp;");
		setDescription("");
		setDetails("");
		setOrderNotice("");
		setScmNotice("");
		setEditsupplier("");
		setEditbrand("");
		setBrandParam("");
		setBrandName("");
		setPm("");
		setOrganization("");
		setEditDeliverGeoRange("");
		setSupplierCompanyName("");
		categoryPath = "";
		setExpireManage("EM01");
		setIsAntiUnpacking("N");
		setGraphicType("S");
		setPrpsShelfPrice("");
		setIsValidateNum("N");
		// 清空category相關參數
		mainCategoryName = "";
		setMainCategory = "";
		mainCategoryId = "";
		flag01 = "";
		flag02 = "";
		flag03 = "";
		flag04 = "";
		flag05 = "";
		flag06 = "";
		flag07 = "";
		flag08 = "";
		flag09 = "";
		flag10 = "";
		flag11 = "";
		flag12 = "";
		flag13 = "";
		flag14 = "";
		flag15 = "";
		flag16 = "";
		setCopy("N");
		return "edit";
	}

	/**
	 * 复制商品
	 * 
	 * @return
	 * @throws Exception
	 */
	public String copy() throws Exception {
		if (StringUtils.isBlank(productId) || StringUtils.length(productId) != 8 || !NumberUtils.isNumber(productId)) {
			addActionError("传入参数错误");
			return list();
		}
		Product copyProduct = productService.get(productId);
		if (null == copyProduct) {
			addActionError("查无商品资料(或无该权限查看)");
			return list();
		}
		product = new Product();
		BeanUtils.copyProperties(copyProduct, product, new String[] { "productId" });
		categoryPath = "";
		mainCategoryName = "";
		setMainCategory = "";
		mainCategoryId = "";
		setCopy("Y");

		setBrief(productService.readFromFile(copyProduct.getProductId(), "brief"));
		setDescription(productService.readFromFile(copyProduct.getProductId(), "description"));
		setDetails(productService.readFromFile(copyProduct.getProductId(), "details"));
		setOrderNotice(productService.readFromFile(copyProduct.getProductId(), "orderNotice"));
		setScmNotice(productService.readFromFile(copyProduct.getProductId(), "scmNotice"));
		setIsScm(product.getIsScm());
		setEditsupplier(product.getSupplierId());
		setEditbrand(StringUtils.defaultString(product.getProductBrand()));
		if (null != product.getProductBrand() || StringUtils.isNotBlank(product.getProductBrand())) {
			Brand brand = productService.getBrandByBrandId(product.getProductBrand());
			if (null != productService.getBrandByBrandId(product.getProductBrand())) {
				setBrandName(brand.getBrandName());
			} else {
				setBrandName("");
			}
		} else {
			setBrandName("");
		}

		setPm(product.getPmID());
		setOrganization(product.getOrganizationPath());
		setEditDeliverGeoRange(product.getDeliverGeoRange());
		setProductAttribute(product.getIsDelete());
		setExpireManage(product.getExpireManage());
		setIsAntiUnpacking(product.getIsAntiUnpacking());
		setGraphicType(product.getGraphicType());
		setIsValidateNum(product.getIsValidateNum());
		setUseDeliveryDay(product.getUseDeliveryDay());
		setDeliveryDay(product.getDeliveryDay());
		if (product.getProductType() == 7) {
			product.setProductType(0);
			setType("0");
		} else {
			setType(String.valueOf(product.getProductType()));
		}
		// 查询已选的主分类详细路径
		if (null != category) {
			mainCategoryName = categoryService.makeCategorieURL(Long.valueOf(product.getMainCategoryID()), false);
		}
		productPromotionFlag = productService.getProductPromotionFlag(productId);
		fileMap = new HashMap<String, String>();
		fileMap = readProductFromFile(productId);
		categoryPath = product.getCategory().getCategoryPath();
		SupplierApply supplierApply = supplierApplyService.get(product.getSupplierId());
		if (null != supplierApply) {
			supplierCompanyName = supplierApply.getCompanyName();
		}
		if (StringUtils.isNotBlank(product.getTwSupplierId())) {
			SupplierApply twSupplierApply = supplierApplyService.get(product.getTwSupplierId());
			if (null != twSupplierApply) {
				editTwSupplier = product.getTwSupplierId();
				twSupplierCompanyName = twSupplierApply.getCompanyName();
			}
		}
		if (null != productPromotionFlag) {
			if (StringUtils.isNotBlank(productPromotionFlag.getFlag04())) {
				flag04 = "true";
			} else {
				flag04 = "";
			}
			if (StringUtils.isNotBlank(productPromotionFlag.getFlag05())) {
				flag05 = "true";
			} else {
				flag05 = "";
			}

			if (StringUtils.isNotBlank(productPromotionFlag.getFlag06())) {
				flag06 = "true";
			} else {
				flag06 = "";
			}
			if (StringUtils.isNotBlank(productPromotionFlag.getFlag16())) {
				flag16 = "true";
			} else {
				flag16 = "";
			}
		}
		productId = "";

		return "edit";
	}

	public String jsonChk24Hr() throws Exception {
		hr24Result = null;
		product = productService.get(productId);
		CommonCriteria crit = new CommonCriteria();
		crit.addEq("productId", productId);
		crit.addEq("approveStatus", "30");
		List<ProductSupplierApprove> psaList = productSupplierApproveService.getList(0, -1, crit,
				new String[] { "id desc" });
		if (psaList.size() > 0) {
			// 審核成功/失敗後24小時的日期
			Date hr24 = DateUtils.addDays(psaList.get(0).getApproveDate(), 1);
			if (new Date().before(hr24)) {
				hr24Result = "24小时内不可再异动";
			}
		}
		return "jsonChk24Hr";
	}

	/* 編輯商品 */
	public String edit() throws Exception {
		// 暂时性的做法，全部导到新增的双属性页面
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		response.sendRedirect(ServerValue.getMidContextPath() + "/product2/edit.do?productId=" + productId);
		categoryPath = "";
		mainCategoryName = "";
		setMainCategory = "";
		mainCategoryId = "";
		product = null;
		if (StringUtils.isBlank(productId) || StringUtils.length(productId) != 8 || !NumberUtils.isNumber(productId)) {
			addActionError("传入参数错误");
			return list();
		}
		product = productService.get(productId);
		if (null == product) {
			addActionError("查无商品资料(或无该权限查看)");
			return list();
		}
		setCopy("N");
		CommonCriteria crit = new CommonCriteria();
		crit.addEq("mainProductId", product.getProductId());
		crit.addGe("addOnPrice", new BigDecimal(0));
		crit.addEq("isDelete", "N");
		crit.addLe("startDate", new Date());
		crit.addGe("endDate", new Date());
		addonsMain = productService.getAddOnProductList(0, -1, crit, null);

		crit = new CommonCriteria();
		crit.addEq("addOnProductId", product.getProductId());
		crit.addGe("addOnPrice", new BigDecimal(0));
		crit.addEq("isDelete", "N");
		crit.addLe("startDate", new Date());
		crit.addGe("endDate", new Date());
		addons = productService.getAddOnProductList(0, -1, crit, null);

		crit = new CommonCriteria();
		crit.addEq("addOnProductId", product.getProductId());
		crit.addGe("addOnPrice", new BigDecimal(-1));
		crit.addEq("isDelete", "N");
		crit.addLe("startDate", new Date());
		crit.addGe("endDate", new Date());
		nms = productService.getAddOnProductList(0, -1, crit, null);

		if (StringUtils.isBlank(product.getIsScm())) {
			isScm = StringUtils.defaultString(product.getIsScm(), "B");
		}
		crit = new CommonCriteria();
		crit.addEq("productId", product.getProductId());
		crit.addEq("approveStatus", "10");
		approveSize = productSupplierApproveService.getListSize(crit).intValue();

		chkHasInventory = productService.chkProductHasInventory(product);
		setBrief(productService.readFromFile(product.getProductId(), "brief"));
		setDescription(productService.readFromFile(product.getProductId(), "description"));
		setDetails(productService.readFromFile(product.getProductId(), "details"));
		setOrderNotice(productService.readFromFile(product.getProductId(), "orderNotice"));
		setScmNotice(productService.readFromFile(product.getProductId(), "scmNotice"));
		setEditsupplier(product.getSupplierId());
		setEditbrand(StringUtils.defaultString(product.getProductBrand()));
		if (null != product.getProductBrand() || StringUtils.isNotBlank(product.getProductBrand())) {
			// setBrandParam(product.getProductBrand());
			Brand brand = productService.getBrandByBrandId(product.getProductBrand());
			if (null != productService.getBrandByBrandId(product.getProductBrand())) {
				setBrandName(brand.getBrandName());
			} else {
				setBrandName("");
			}
		} else {
			// setBrandParam("");
			setBrandName("");
		}
		setPm(product.getPmID());
		setOrganization(product.getOrganizationPath());
		setEditDeliverGeoRange(product.getDeliverGeoRange());
		setProductAttribute(product.getIsDelete());
		setIsScm(product.getIsScm());
		setExpireManage(product.getExpireManage());
		setIsAntiUnpacking(product.getIsAntiUnpacking());
		setGraphicType(product.getGraphicType());
		setIsValidateNum(product.getIsValidateNum());
		setUseDeliveryDay(product.getUseDeliveryDay());
		setDeliveryDay(product.getDeliveryDay());
		// 查询已选的主分类详细路径
		if (null != category) {
			mainCategoryName = categoryService.makeCategorieURL(Long.valueOf(product.getMainCategoryID()), false);
		}

		productPromotionFlag = productService.getProductPromotionFlag(productId);
		fileMap = new HashMap<String, String>();
		fileMap = readProductFromFile(productId);
		categoryPath = product.getCategory().getCategoryPath();

		SupplierApply supplierApply = supplierApplyService.get(product.getSupplierId());
		if (null != supplierApply) {
			supplierCompanyName = supplierApply.getCompanyName();
		}

		if (StringUtils.isNotBlank(product.getTwSupplierId())) {
			SupplierApply twSupplierApply = supplierApplyService.get(product.getTwSupplierId());
			if (null != twSupplierApply) {
				editTwSupplier = product.getTwSupplierId();
				twSupplierCompanyName = twSupplierApply.getCompanyName();
			}
		}

		if (null != productPromotionFlag) {
			if (StringUtils.isNotBlank(productPromotionFlag.getFlag04())) {
				flag04 = "true";
			} else {
				flag04 = "";
			}

			if (StringUtils.isNotBlank(productPromotionFlag.getFlag05())) {
				flag05 = "true";
			} else {
				flag05 = "";
			}

			if (StringUtils.isNotBlank(productPromotionFlag.getFlag06())) {
				flag06 = "true";
			} else {
				flag06 = "";
			}

			if (StringUtils.isNotBlank(productPromotionFlag.getFlag16())) {
				flag16 = "true";
			} else {
				flag16 = "";
			}
		}
		return "edit";
	}

	/**
	 * 载入新增/编辑商品目录
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editCategoryConfig() throws Exception {
		if (StringUtils.isBlank(productId) || StringUtils.length(productId) != 8 || !NumberUtils.isNumber(productId)) {
			addActionError("传入参数错误");
			return list();
		}
		product = productService.get(productId);
		if (null == product) {
			addActionError("查无商品资料(或无该权限查看)");
			return list();
		}
		CommonCriteria crit = new CommonCriteria();
		crit.addEq("productId", productId);
		productCategories = productService.getProductCategoryList(0, -1, crit, null);
		productCategoryMap = findProductCategoryMap(productCategories, product);
		// 主目录id
		mainCategory = Long.parseLong(String.valueOf(product.getMainCategoryID()));
		// 主目录路径
		mainCategoryText = categoryService.makeCategorieURL(Long.parseLong(String.valueOf(product.getMainCategoryID())),
				false);

		User user = AdminHelper.getUser();
		if (null != user) {
			// 若 user 是 PM部門, 檢核 product.category 的 orgnizationPath 是否合乎規定
			int i = 0;
			for (UserPermission up : user.getPermissions(Type.CATEGORY).values()) {
				userPermissions = userPermissions + StringUtils.trim(up.getPermissionCode());
				if (i != user.getPermissions(Type.CATEGORY).values().size() - 1) {
					userPermissions = userPermissions + ",";
				}
				i++;
			}
		}
		return "editCategoryConfig";
	}

	/**
	 * 修改商品属性
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editProductAttribute() throws Exception {
		if (prdtDelete != null) {
			for (int i = 0; i < prdtDelete.length; i++) {
				product = productService.get(prdtDelete[i]);
				product.setIsDelete(productAttribute);
				productService.update(product);
			}
		}
		return list();
	}

	// 若该商品已被列入搭售时,规格只能有一个,不可以再新增规格
	public String findAddonProdSpec() throws Exception {
		if (StringUtils.isNotBlank(productId)) {
			CommonCriteria crit = new CommonCriteria();
			crit.addEq("addOnProductId", productId);
			crit.addEq("isEnable", "Y");
			crit.addEq("isDelete", "N");
			int iAddOnSpec = productService.getAddOnProductList(0, -1, crit, null).size();
			if (iAddOnSpec > 0) {
				jsonAddonProdSpec = "canOnlyOneSpec";
			} else {
				jsonAddonProdSpec = "canMoreSpec";
			}
		}
		return "jsonFindAddonProdSpec";
	}

	public String findCategoryPath() throws Exception {
		if (StringUtils.isNotBlank(categoryId)) {
			Long tempCategoryId = Long.parseLong(categoryId);
			jsonCategoryPath = categoryService.get(tempCategoryId).getCategoryPath();
		}
		return "jsonFindCategoryPath";
	}

	public String findSupplierApply() throws Exception {
		if (StringUtils.isNotBlank(editsupplier)) {
			sp = supplierApplyService.get(editsupplier);
			if (StringUtils.isNotBlank(sp.getShipAddr()) && StringUtils.isNotBlank(sp.getShipProvince())
					&& StringUtils.isNotBlank(sp.getShipCity()) && StringUtils.isNotBlank(sp.getShipArea())
					&& StringUtils.isNotBlank(sp.getShipContact()) && StringUtils.isNotBlank(sp.getShipZip())
					&& StringUtils.isNotBlank(sp.getShipPhone())) {
				spResult = "true," + sp.getIsScm();
			} else {
				spResult = "false," + sp.getIsScm();
			}
		} else {
			spResult = "false," + sp.getIsScm();
		}
		return "jsonFindSupplierApply";
	}

	Map<Long, String> findProductCategoryMap(List<ProductCategory> productCategories, Product product)
			throws CoreException {
		productCategoryMap = new HashMap<Long, String>();
		for (ProductCategory productCategory : productCategories) {
			productCategoryMap.put(productCategory.getCategoryId(), categoryService.makeCategorieURL(productCategory
					.getCategoryId(), false)
					+ "," + productCategory.getCategoryPath() + "," + productCategory.getShowSeq());
		}
		return productCategoryMap;
	}

	public Menu getAttributeMenu() {
		return attributeMenu;
	}

	/**
	 * @return the band
	 */
	public String getBrand() {
		return brand;
	}

	public String getBrandName() {
		return brandName;
	}

	public String getBrandParam() {
		return brandParam;
	}

	/**
	 * @return the brands
	 */
	public List<Brand> getBrands() {
		return brands;
	}

	/**
	 * @return the brief
	 */
	public String getBrief() {
		return brief;
	}

	public Category getCategory() {
		return category;
	}

	public String getCategoryId() {
		return categoryId;
	}

	public String getCategoryIdParam() {
		return categoryIdParam;
	}

	public String getCategoryLevel1Param() {
		return categoryLevel1Param;
	}

	public String getCategoryLevel2Param() {
		return categoryLevel2Param;
	}

	public String getCategoryPath() {
		return categoryPath;
	}

	public String getCategoryResult() {
		return categoryResult;
	}

	/**
	 * @return the categoryRoot
	 */
	public List<Category> getCategoryRoot() {
		return categoryRoot;
	}

	/**
	 * @return the categoryService
	 */
	public CategoryService getCategoryService() {
		return categoryService;
	}

	/**
	 * @return the cost
	 */
	public String getCost() {
		return cost;
	}

	/**
	 * @return the delivertolerance
	 */
	public String getDelivertolerance() {
		return delivertolerance;
	}

	/**
	 * @return the delSelectedCategory
	 */
	public String[] getDelSelectedCategory() {
		return delSelectedCategory;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @return the details
	 */
	public String getDetails() {
		return details;
	}

	public String getEditbrand() {
		return editbrand;
	}

	/**
	 * @return the editDeliverGeoRange
	 */
	public String getEditDeliverGeoRange() {
		return editDeliverGeoRange;
	}

	public String getEditFlag() {
		return editFlag;
	}

	/**
	 * @return the editleadtime
	 */
	public String getEditleadtime() {
		return editleadtime;
	}

	public List<ProductCategory> getEditProductCategories() {
		return editProductCategories;
	}

	/**
	 * @return the editsupplier
	 */
	public String getEditsupplier() {
		return editsupplier;
	}

	public String getExpectShipDate() {
		return expectShipDate;
	}

	public Map<String, String> getFileMap() {
		return fileMap;
	}

	public String getFinalAddOnData() {
		return finalAddOnData;
	}

	public String getFlag01() {
		return flag01;
	}

	public String getFlag02() {
		return flag02;
	}

	public String getFlag03() {
		return flag03;
	}

	public String getFlag04() {
		return flag04;
	}

	public String getFlag05() {
		return flag05;
	}

	public String getFlag06() {
		return flag06;
	}

	public String getFlag07() {
		return flag07;
	}

	public String getFlag08() {
		return flag08;
	}

	public String getFlag09() {
		return flag09;
	}

	public String getFlag10() {
		return flag10;
	}

	public String getFlag11() {
		return flag11;
	}

	public String getFlag12() {
		return flag12;
	}

	public String getFlag13() {
		return flag13;
	}

	public String getFlag14() {
		return flag14;
	}

	public String getFlag15() {
		return flag15;
	}

	public String getFlag16() {
		return flag16;
	}

	public Menu getFreightMenu() {
		return freightMenu;
	}

	public List<Group> getGroups() {
		return groups;
	}

	/**
	 * @return the height
	 */
	public String getHeight() {
		return height;
	}

	public String getIsPmGroup() {
		return isPmGroup;
	}

	public String getJsonAddonProdSpec() {
		return jsonAddonProdSpec;
	}

	/**
	 * 判断是否为最底层的目录
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String getJsonCategoryData() throws CoreException {
		category = categoryService.get(Long.parseLong(mainCategoryId));
		categoryResult = category.getIsEndnode();
		return "jsonCategoryData";
	}

	public String getJsonCategoryPath() {
		return jsonCategoryPath;
	}

	public String getJsonOrderNotice() {
		return jsonOrderNotice;
	}

	/**
	 * @return the keyword
	 */
	public String getKeyword() {
		return keyword;
	}

	public String getLastMainCategoryId() {
		return lastMainCategoryId;
	}

	/**
	 * @return the length
	 */
	public String getLength() {
		return length;
	}

	public Long getMainCategory() {
		return mainCategory;
	}

	public String getMainCategoryId() {
		return mainCategoryId;
	}

	/**
	 * @return the mainCategoryName
	 */
	public String getMainCategoryName() {
		return mainCategoryName;
	}

	public String getMainCategoryText() {
		return mainCategoryText;
	}

	public Map<String, String> getMapRootCategories() {
		return mapRootCategories;
	}

	/**
	 * @return the maxpo
	 */
	public String getMaxpo() {
		return maxpo;
	}

	/**
	 * @return the memo
	 */
	public String getMemo() {
		return memo;
	}

	/**
	 * @return the minpo
	 */
	public String getMinpo() {
		return minpo;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	public String getOrderNotice() {
		return orderNotice;
	}

	/**
	 * @return the organization
	 */
	public String getOrganization() {
		return organization;
	}

	/**
	 * @return the pager
	 */
	public SimplePager getPager() {
		return pager;
	}

	/**
	 * @return the pm
	 */
	public String getPm() {
		return pm;
	}

	public String getPmIdParam() {
		return pmIdParam;
	}

	/**
	 * @return the prdtDelete
	 */
	public String[] getPrdtDelete() {
		return prdtDelete;
	}

	/**
	 * @return the price
	 */
	public String getPrice() {
		return price;
	}

	/**
	 * @return the product
	 */
	public Product getProduct() {
		return product;
	}

	public String getProductAttribute() {
		return productAttribute;
	}

	public String getProductAttributeParam() {
		return productAttributeParam;
	}

	public List<ProductCategory> getProductCategories() {
		return productCategories;
	}

	public Map<Long, String> getProductCategoryMap() {
		return productCategoryMap;
	}

	/**
	 * @return the productId
	 */
	public String getProductId() {
		return productId;
	}

	/**
	 * @return the productIdParam
	 */
	public String getProductIdParam() {
		return productIdParam;
	}

	/**
	 * @return the productNameParam
	 */
	public String getProductNameParam() {
		return productNameParam;
	}

	public ProductPromotionFlag getProductPromotionFlag() {
		return productPromotionFlag;
	}

	/**
	 * @return the products
	 */
	public List<Product> getProducts() {
		return products;
	}

	/**
	 * @return the productService
	 */
	public ProductService getProductService() {
		return productService;
	}

	public String getProductStParam() {
		return productStParam;
	}

	public String getProductTypeParam() {
		return productTypeParam;
	}

	/**
	 * @return the returnable
	 */
	public String getReturnable() {
		return returnable;
	}

	/**
	 * @return the returnpickup
	 */
	public String getReturnpickup() {
		return returnpickup;
	}

	public List<Category> getRootCategories() {
		return rootCategories;
	}

	/**
	 * @return the rsmap
	 */
	public Map<String, String> getRsmap() {
		return rsmap;
	}

	/**
	 * @return the selectedcategories
	 */
	public List<ProductCategory> getSelectedcategories() {
		return selectedcategories;
	}

	/**
	 * @return the setMainCategory
	 */
	public String getSetMainCategory() {
		return setMainCategory;
	}

	public String getSetMainSupplier() {
		return setMainSupplier;
	}

	/**
	 * @return the showSelectedCategory
	 */
	public String getShowSelectedCategory() {
		return showSelectedCategory;
	}

	public String getShowSeq() {
		return showSeq;
	}

	public String[] getShowSpecSeq() {
		return showSpecSeq;
	}

	/**
	 * @return the spcBarCode
	 */
	public String[] getSpcBarCode() {
		return spcBarCode;
	}

	/**
	 * @return the spcCode
	 */
	public String[] getSpcCode() {
		return spcCode;
	}

	/**
	 * @return the spcDelete
	 */
	public String[] getSpcDelete() {
		return spcDelete;
	}

	public String[] getSpcHotSaleInventory() {
		return spcHotSaleInventory;
	}

	/**
	 * @return the spcId
	 */
	public String[] getSpcId() {
		return spcId;
	}

	/**
	 * @return the spcMaxCountPerOrder
	 */
	public String[] getSpcMaxCountPerOrder() {
		return spcMaxCountPerOrder;
	}

	/**
	 * @return the spcMinCountPerOrder
	 */
	public String[] getSpcMinCountPerOrder() {
		return spcMinCountPerOrder;
	}

	/**
	 * @return the spcName
	 */
	public String[] getSpcName() {
		return spcName;
	}

	/**
	 * @return the spcReverseInventory
	 */
	public String[] getSpcReverseInventory() {
		return spcReverseInventory;
	}

	/**
	 * @return the spcSafeInventory
	 */
	public String[] getSpcSafeInventory() {
		return spcSafeInventory;
	}

	/**
	 * @return the specification
	 */
	public Specification getSpecification() {
		return specification;
	}

	/**
	 * @return the specificationinventory
	 */
	public SpecificationInventory getSpecificationinventory() {
		return specificationinventory;
	}

	public Map<Long, List<Integer>> getSpecificationinventoryMap() {
		return specificationinventoryMap;
	}

	/**
	 * @return the specificationinventorys
	 */
	public List<SpecificationInventory> getSpecificationinventorys() {
		return specificationinventorys;
	}

	/**
	 * @return the specifications
	 */
	public List<Specification> getSpecifications() {
		return specifications;
	}

	public String[] getSpecStatus() {
		return specStatus;
	}

	public Menu getSpecStatusMenu() {
		return specStatusMenu;
	}

	public String getSpecStatusParam() {
		return specStatusParam;
	}

	public Menu getSpecSubStatusMenu() {
		return specSubStatusMenu;
	}

	public List<Object> getStockReports() {
		return stockReports;
	}

	public SupplierApplyService getSupplierApplyService() {
		return supplierApplyService;
	}

	public String getSupplierCompanyName() {
		return supplierCompanyName;
	}

	/**
	 * @return the supplierDelete
	 */
	public String[] getSupplierDelete() {
		return supplierDelete;
	}

	public String getSupplierParam() {
		return supplierParam;
	}

	/**
	 * @return the suppliers
	 */
	public Collection<SupplierApply> getSuppliers() {
		return suppliers;
	}

	/**
	 * @return the tax
	 */
	public String getTax() {
		return tax;
	}

	/**
	 * @return the temperature
	 */
	public String getTemperature() {
		return temperature;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @return the unit
	 */
	public String getUnit() {
		return unit;
	}

	public List<User> getUsers() {
		return users;
	}

	/**
	 * @return the virtual
	 */
	public String getVirtual() {
		return virtual;
	}

	/**
	 * @return the volume
	 */
	public String getVolume() {
		return volume;
	}

	/**
	 * @return the weight
	 */
	public String getWeight() {
		return weight;
	}

	/**
	 * @return the width
	 */
	public String getWidth() {
		return width;
	}

	/* 商品列表 */
	public String list() throws Exception {
		// 暂时性的做法，全部导到新增的双属性页面
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		response.sendRedirect(ServerValue.getMidContextPath() + "/product2/list.do");

		String categoryPathParam = "";
		if (StringUtils.isNotBlank(categoryLevel1Param) && StringUtils.isNotBlank(categoryLevel2Param)) {
			categoryPathParam = categoryLevel1Param + "/" + categoryLevel2Param;
		} else if (StringUtils.isNotBlank(categoryLevel1Param) && StringUtils.isBlank(categoryLevel2Param)) {
			categoryPathParam = categoryLevel1Param + "/";
		}
		Map<String, String> searchMap = new HashMap<String, String>();
		searchMap.put("productId", productIdParam);
		searchMap.put("productName", productNameParam);
		searchMap.put("isDelete", productAttributeParam);
		searchMap.put("productType", productTypeParam);
		searchMap.put("supplierId", supplierParam);
		searchMap.put("categoryPath", categoryPathParam);
		searchMap.put("productBrand", brandParam);
		searchMap.put("isScm", scmParam);
		long entitySize = productService.getProductPageableListSize(searchMap).longValue();
		pager.setTotalSize(entitySize);
		products = productService.getProductPageableList(searchMap, pager.getCurrentPage() * pager.getPageRecord(), pager
				.getPageRecord());

		// 取得商品可購數
		if (null != products) {
			rsmap = productService.getSpecificationinventoryDaoSum(products);
		}
		return "list";
	}

	/**
	 * 动态载入购物须知
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String loadOrderNotice() throws CoreException {
		category = categoryService.get(Long.parseLong(categoryId));

		if (category.getLevel() == "0") {
			jsonOrderNotice = productService.readOrderNotice(categoryId);
		} else {
			jsonOrderNotice = productService.readOrderNotice(category.getCategoryPath().split("/")[0]);
		}
		return "jsonLoadOrderNotice";
	}

	public void prepare() throws Exception {
		clearErrorsAndMessages();
		if (pager == null) {
			pager = new SimplePager();
		}
		pager.setPageRecord(20);// defaut 20

		if (null == rootCategories) {
			rootCategories = categoryService.getChild(0l);
			mapRootCategories = new HashMap<String, String>();
			for (Category rootCategory : rootCategories) {
				mapRootCategories.put(rootCategory.getId().toString(), rootCategory.getName());
			}
		}

		// 找出所有ｐｍ的user
		if (null == users) {
			users = userService.getByRole(Role.Default.PM.name(), Role.Type.OTHER);
		}

		// 运送区域
		if (null == freightMenu) {
			freightMenu = menuService.get("Freight.key");
		}

		// 找出a-20的部門
		groups = groupService.getList(0, -1, new CommonCriteria().addRlike("code", EcConstant.PRODUCT_PM_GROUP_CODE),
				new String[] { "code" });

		// 商品属性
		attributeMenu = menuService.get("Product.Attribute");

		// 规格属性
		specStatusMenu = menuService.get("Spec.Status");

		// 规格状态
		if (null == specSubStatusMenu) {
			specSubStatusMenu = menuService.get("Specification.SpecStatus");
		}

		// 效期管理分类
		if (null == expireManageMenu) {
			expireManageMenu = menuService.get("ExpireManage.Attribute");
		}

		if (null == orderStMenu) {
			orderStMenu = menuService.get("Order.status.md");
		}

		if (StringUtils.isNotBlank(productIdParam)) {
			setProductIdParam(productIdParam);
		}
		if (StringUtils.isNotBlank(productNameParam)) {
			setProductNameParam(productNameParam);
		}
		if (StringUtils.isNotBlank(productAttributeParam)) {
			setProductAttributeParam(productAttributeParam);
		}
		if (StringUtils.isNotBlank(productTypeParam)) {
			setProductTypeParam(productTypeParam);
		}
		if (StringUtils.isNotBlank(specStatusParam)) {
			setSpecStatusParam(specStatusParam);
		} else {
			setSpecStatusParam("N");
		}
		if (StringUtils.isNotBlank(categoryLevel1Param)) {
			setCategoryLevel1Param(categoryLevel1Param);
		}
		if (StringUtils.isNotBlank(categoryLevel2Param)) {
			setCategoryLevel2Param(categoryLevel2Param);
		}
		if (StringUtils.isNotBlank(supplierParam)) {
			setSupplierParam(supplierParam);
		}
		if (StringUtils.isNotBlank(brandParam)) {
			setBrandParam(brandParam);
		}
		totalInventory = 0;
		totalHotSale = 0;
		stockQty = 0;
		userPermissions = "";
	}

	/**
	 * 读商品活动简介／特色、商品活动说明文字、商品活动规格内容檔案
	 * 
	 * @param product
	 * @return
	 * @throws CoreException
	 */
	Map<String, String> readProductFromFile(String productId) throws CoreException {
		Map<String, String> tempMap = new HashMap<String, String>();
		tempMap.put("brief", productService.readFromFile(productId, "brief"));
		tempMap.put("description", productService.readFromFile(productId, "description"));
		tempMap.put("details", productService.readFromFile(productId, "details"));
		tempMap.put("orderNotice", productService.readFromFile(productId, "orderNotice"));
		tempMap.put("scmNotice", productService.readFromFile(productId, "scmNotice"));
		return tempMap;
	}

	/**
	 * 儲存商品資料
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws Exception {
		final BigDecimal tempBigDecimal = new BigDecimal(0).setScale(2, BigDecimal.ROUND_FLOOR);
		product = null;
		if (StringUtils.isNotBlank(productId)) {
			product = productService.get(productId);
			if (null == product) {
				addActionError("查无商品资料(或无该权限查看)");
				return "edit";
			}
			// isScm = product.getIsScm();
			category = categoryService.get(Long.valueOf(String.valueOf(mainCategoryId)));
			product.setOldMainCategoryID(product.getMainCategoryID());
			if (null == category || category.getIsDelete().equalsIgnoreCase("Y")) {
				addActionError("儲存失敗,主分类资料不正确");
				return "edit";
			}
			Category rootCategory = categoryService.get(Long.parseLong(category.getCategoryPath().split("/")[0]));
			if (null == rootCategory) {
				addActionError("儲存失敗,主分类资料不正确");
				return "edit";
			}
			if (rootCategory.getIsDelete().equals("Y")) {
				addActionError("儲存失敗,主分类资料不正确");
				return "edit";
			}
			// 中台在設定預購時是不是要檢查是否有設定N選M or 搭售
			if (StringUtils.equals("1", type)) {
				CommonCriteria crit = new CommonCriteria();
				crit.addEq("mainProductId", productId);
				crit.addEq("isDelete", "N");
				crit.addLe("startDate", new Date());
				crit.addGe("endDate", new Date());
				List<AddOnProduct> addOnProducts = productService.getAddOnProductList(0, -1, crit, null);
				if (addOnProducts.size() > 0) {
					addActionError("商品不可设为预购，已存在于N選M or 搭售");
					return "edit";
				}
				crit = new CommonCriteria();
				crit.addEq("addOnProductId", productId);
				crit.addEq("isDelete", "N");
				crit.addLe("startDate", new Date());
				crit.addGe("endDate", new Date());
				addOnProducts = productService.getAddOnProductList(0, -1, crit, null);
				if (addOnProducts.size() > 0) {
					addActionError("商品不可设为预购，已存在于N選M or 搭售");
					return "edit";
				}
			}
			if (null == product.getProductPromotionFlag()) {
				productPromotionFlag = new ProductPromotionFlag();
			} else {
				productPromotionFlag = product.getProductPromotionFlag();
			}
		} else {
			product = new Product();
			productPromotionFlag = new ProductPromotionFlag();
			if (StringUtils.isBlank(cost)) {
				product.setProductCost(new BigDecimal(0).setScale(2, BigDecimal.ROUND_FLOOR));
			} else {
				product.setProductCost(new BigDecimal(cost).setScale(2, BigDecimal.ROUND_FLOOR));
			}
		}

		if (StringUtils.isNotBlank(name)) {
			product.setProductName(name);
		}
		product.setProductType(Integer.valueOf(type));
		product.setIsVirtual(virtual);
		if (StringUtils.isNotBlank(isScm)) {
			product.setIsScm(isScm);
		}
		product.setListPrice(new BigDecimal(price).setScale(1, BigDecimal.ROUND_FLOOR));
		product.setTaxClass(tax);
		if (StringUtils.isNotBlank(editleadtime)) {
			product.setLeadTime(Integer.valueOf(editleadtime));
		}

		if (StringUtils.isNotBlank(delivertolerance)) {
			product.setIsDeliverTolerance(delivertolerance);
		} else {
			product.setIsDeliverTolerance("N");
		}

		product.setDeliverGeoRange(editDeliverGeoRange);
		if (StringUtils.isNotBlank(length)) {
			product.setProductLength(new BigDecimal(length).setScale(2, BigDecimal.ROUND_FLOOR));
		} else {
			product.setProductLength(tempBigDecimal);
		}

		if (StringUtils.isNotBlank(width)) {
			product.setProductWidth(new BigDecimal(width).setScale(2, BigDecimal.ROUND_FLOOR));
		} else {
			product.setProductWidth(tempBigDecimal);
		}

		if (StringUtils.isNotBlank(height)) {
			product.setProductHeight(new BigDecimal(height).setScale(2, BigDecimal.ROUND_FLOOR));
		} else {
			product.setProductHeight(tempBigDecimal);
		}

		if (StringUtils.isNotBlank(weight)) {
			product.setProductWeight(new BigDecimal(weight).setScale(2, BigDecimal.ROUND_FLOOR));
		} else {
			product.setProductWeight(tempBigDecimal);
		}

		if (StringUtils.isNotBlank(volume)) {
			product.setProductVolume(new BigDecimal(volume).setScale(2, BigDecimal.ROUND_FLOOR));
		} else {
			product.setProductVolume(tempBigDecimal);
		}

		product.setProductUnit(unit);
		if (!"0".equals(minpo)) {
			product.setMinPOQuantity(Integer.valueOf(minpo));
		}
		if (!"0".equals(maxpo)) {
			product.setMaxPOQuantity(Integer.valueOf(maxpo));
		}
		if (!"0".equals(temperature)) {
			product.setTemperatureType(Integer.valueOf(temperature));
		}

		if (StringUtils.isNotBlank(returnpickup)) {
			product.setIsReturnPickup(returnpickup);
		} else {
			product.setIsReturnPickup("Y");
		}

		if (StringUtils.isNotBlank(returnable)) {
			product.setIsReturnable(returnable);
		} else {
			product.setIsReturnable("Y");
		}

		if (StringUtils.isNotBlank(expireManage)) {
			product.setExpireManage(expireManage);
		} else {
			product.setExpireManage("EM01");
		}

		if (StringUtils.isNotBlank(isAntiUnpacking)) {
			product.setIsAntiUnpacking(isAntiUnpacking);
		} else {
			product.setIsAntiUnpacking("N");
		}
		if (StringUtils.isNotBlank(graphicType)) {
			product.setGraphicType(graphicType);
		} else {
			product.setGraphicType("S");
		}
		if (StringUtils.isNotBlank(isValidateNum)) {
			product.setIsValidateNum(isValidateNum);
		} else {
			product.setIsValidateNum("N");
		}
		if (StringUtils.isNotBlank(useDeliveryDay)) {
			product.setUseDeliveryDay(useDeliveryDay);
		} else {
			product.setUseDeliveryDay("N");
		}
		product.setDeliveryDay(deliveryDay);
		product.setSupplierId(editsupplier);
		if (Arrays.asList("010000", "010001").contains(editsupplier)) {
			if (StringUtils.equalsIgnoreCase("Y", product.getIsScm())) {
				addActionError("若供应商为万美供应商，采购模式不可为转单");
				return "edit";
			}
			if (StringUtils.isNotBlank(editTwSupplier)) {
				product.setTwSupplierId(editTwSupplier);
			} else {
				product.setTwSupplierId("");
			}
		}
		product.setProductBrand(editbrand);
		product.setPmID(pm);
		product.setOrganizationPath(organization);
		product.setProductMemo(memo);
		product.setProductKeyword(keyword);
		product.setIsDelete(productAttribute);
		product.setPickupQty(0);// 非n选m的商品一律设为0
		product.setProductStatus("PRD500");
		product.setProductBrief(brief);
		product.setProductDescription(description);
		product.setProductDetails(details);
		if (StringUtils.isNotBlank(scmNotice)) {
			product.setScmNotice(scmNotice);
		}
		if (StringUtils.equals("1", type)) {
			product.setExpectShipDate(format.parse(expectShipDate));
		} else {
			product.setExpectShipDate(null);
		}
		if (StringUtils.isBlank(prpsShelfPrice)) {
			product.setPrpsShelfPrice(new BigDecimal(0).setScale(2, BigDecimal.ROUND_FLOOR));
		} else {
			product.setPrpsShelfPrice(new BigDecimal(prpsShelfPrice).setScale(2, BigDecimal.ROUND_FLOOR));
		}
		if (StringUtils.isNotBlank(orderNotice)) {
			product.setProductOrderNotice(orderNotice);
		}

		if (StringUtils.isNotBlank(showSeq)) {
			product.setShowSeq(Integer.parseInt(showSeq));
		}

		if (StringUtils.isNotBlank(mainCategoryId)) {
			Category category = categoryService.get(Long.valueOf(mainCategoryId));
			product.setMainCategoryID(Integer.valueOf(mainCategoryId));
			product.setMainCategoryPath(category.getCategoryPath());
			product.setCategory(category);
		}
		if (StringUtils.isNotBlank(tax)) {
			product.setTaxClass(tax);
		}

		if (StringUtils.equalsIgnoreCase(flag04, "Y")) {
			productPromotionFlag.setFlag04(flag04);
		} else {
			productPromotionFlag.setFlag04(null);
		}

		if (StringUtils.equalsIgnoreCase(flag05, "Y")) {
			productPromotionFlag.setFlag05(flag05);
		} else {
			productPromotionFlag.setFlag05(null);
		}

		if (StringUtils.equalsIgnoreCase(flag06, "Y")) {
			productPromotionFlag.setFlag06(flag06);
		} else {
			productPromotionFlag.setFlag06(null);
		}

		if (StringUtils.equalsIgnoreCase(flag16, "Y")) {
			productPromotionFlag.setFlag16(flag16);
		} else {
			productPromotionFlag.setFlag16(null);
		}
		Product newProduct = productService.saveOrUpdateProduct(product, productPromotionFlag);//
		// 新增/修改商品
		productId = newProduct.getProductId();
		addActionMessage("储存完成");
		return edit();
	}

	public String saveCategoryConfig() throws Exception {
		product = productService.get(productIdParam);
		if (null == product) {
			addActionError("查无商品资料(或无该权限查看)");
			return "editCategoryConfig";
		}
		if (StringUtils.isNotBlank(editFlag)) {
			product.setMainCategoryID(Integer.parseInt(lastMainCategoryId));
		}
		String[] splitData = StringUtils.split(finalAddOnData, ";");
		editProductCategories = new ArrayList<ProductCategory>();
		ProductCategory productCategory = null;
		Category category = null;
		String errMsg = "";
		for (int i = 0; i < splitData.length; i++) {
			String[] sUpdate = StringUtils.split(splitData[i], ",");
			category = categoryService.getAvailableCategoryNonePermission(Long.parseLong(sUpdate[0]));
			if (null == category) {
				errMsg = errMsg + sUpdate[0] + ":该目录已下架或已删除\n";
			} else {
				if (category.getIsEndnode().equals("N")) {
					errMsg = errMsg + "请选择最底层的目录:" + category.getAliasName() + ":" + category.getId() + "\n";
				}
			}
		}
		if (StringUtils.isBlank(errMsg)) {
			for (int i = 0; i < splitData.length; i++) {
				String[] sUpdate = StringUtils.split(splitData[i], ",");
				category = categoryService.getCategoryNonePermission(Long.parseLong(sUpdate[0]));
				productCategory = new ProductCategory();
				productCategory.setCategoryId(Long.parseLong(sUpdate[0]));

				productCategory.setCategoryName(category.getName());
				productCategory.setCategoryPath(category.getCategoryPath());
				productCategory.setProductId(product.getProductId());
				productCategory.setShowSeq(Integer.parseInt(sUpdate[2]));
				editProductCategories.add(productCategory);
			}
			productService.saveOrUpdateProductCategoryBatch(product, editProductCategories);
			addActionMessage("储存完成");
		} else {
			addActionError("储存失败:\n" + errMsg);
		}
		productId = product.getProductId();
		return editCategoryConfig();
	}

	/* 新增,删除,修改商品Spec */
	public String saveSpec() throws Exception {
		List<Specification> newSpecs = new ArrayList<Specification>();
		List<Specification> updSpecs = new ArrayList<Specification>();
		List<Specification> delSpecs = new ArrayList<Specification>();
		for (int i = 0; i < spcName.length; i++) {
			if (spcId[i].equals("")) {// save spec
				specification = new Specification();
				specification.setSpecificationName(spcName[i]);
				specification.setBarCode(spcBarCode[i]);
				specification.setSpecCode(spcCode[i]);
				specification.setSpecStatus(specStatus[i]);
				if (!spcReverseInventory[i].equals("") || !spcMaxCountPerOrder[i].equals("")
						|| !spcMinCountPerOrder[i].equals("") || !spcSafeInventory[i].equals("")) {
					specification.setReverseInventory(Integer.parseInt(spcReverseInventory[i]));
					specification.setMaxCountPerOrder(Integer.parseInt(spcMaxCountPerOrder[i]));
					specification.setMinCountPerOrder(Integer.parseInt(spcMinCountPerOrder[i]));
					specification.setSafeInventory(Integer.parseInt(spcSafeInventory[i]));
					specification.setIsDelete("N");
					specification.setProductId(productId);
					specification.setShowSeq(Integer.parseInt(showSpecSeq[i]));
					if (StringUtils.isNotBlank(spcHotSaleInventory[i])) {
						specification.setHotSaleInventory(Integer.parseInt(spcHotSaleInventory[i]));
					}
					newSpecs.add(specification);
				}
			} else {// update spec
				CommonCriteria crit = new CommonCriteria();
				crit.addEq("specificationId", Long.parseLong(spcId[i]));
				specification = productService.getSpecificationList(0, 1, crit, null).get(0);
				specification.setIsDelete("N");
				// specification.setSpecificationName(spcName[i]);不允許修改
				specification.setSpecificationName(specification.getSpecificationName());// 移除脫逸字元/n/r(在entity處理)
				specification.setBarCode(spcBarCode[i]);
				specification.setSpecCode(spcCode[i]);
				specification.setSpecStatus(specStatus[i]);
				specification.setReverseInventory(Integer.parseInt(spcReverseInventory[i]));
				specification.setMaxCountPerOrder(Integer.parseInt(spcMaxCountPerOrder[i]));
				specification.setMinCountPerOrder(Integer.parseInt(spcMinCountPerOrder[i]));
				specification.setSafeInventory(Integer.parseInt(spcSafeInventory[i]));
				specification.setShowSeq(Integer.parseInt(showSpecSeq[i]));
				if (StringUtils.isNotBlank(spcHotSaleInventory[i])) {
					specification.setHotSaleInventory(Integer.parseInt(spcHotSaleInventory[i]));
				}
				updSpecs.add(specification);
			}
		}
		if (null != spcDelete) { // delete spec
			for (int i = 0; i < spcDelete.length; i++) {
				CommonCriteria crit = new CommonCriteria();
				crit.addEq("specificationId", Long.parseLong(spcDelete[i]));
				specification = productService.getSpecificationList(0, 1, crit, null).get(0);
				specification.setIsDelete("Y");
				delSpecs.add(specification);
			}
			spcDelete = null;
		}
		if (!newSpecs.isEmpty() || !updSpecs.isEmpty() || !delSpecs.isEmpty()) {
			productService.saveBatchSpecification(productId, newSpecs, updSpecs, delSpecs);
		}
		addActionMessage("储存完成");
		return spec();
	}

	public void setAttributeMenu(Menu attributeMenu) {
		this.attributeMenu = attributeMenu;
	}

	/**
	 * @param band the band to set
	 */
	public void setBrand(String brand) {
		this.brand = brand;
	}

	public void setBrandName(String brandName) {
		this.brandName = brandName;
	}

	public void setBrandParam(String brandParam) {
		this.brandParam = brandParam;
	}

	/**
	 * @param brands the brands to set
	 */
	public void setBrands(List<Brand> brands) {
		this.brands = brands;
	}

	/**
	 * @param brief the brief to set
	 */
	public void setBrief(String brief) {
		this.brief = brief;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public void setCategoryIdParam(String categoryIdParam) {
		this.categoryIdParam = categoryIdParam;
	}

	public void setCategoryLevel1Param(String categoryLevel1Param) {
		this.categoryLevel1Param = categoryLevel1Param;
	}

	public void setCategoryLevel2Param(String categoryLevel2Param) {
		this.categoryLevel2Param = categoryLevel2Param;
	}

	public void setCategoryPath(String categoryPath) {
		this.categoryPath = categoryPath;
	}

	public void setCategoryResult(String categoryResult) {
		this.categoryResult = categoryResult;
	}

	/**
	 * @param categoryRoot the categoryRoot to set
	 */
	public void setCategoryRoot(List<Category> categoryRoot) {
		this.categoryRoot = categoryRoot;
	}

	/**
	 * @param categoryService the categoryService to set
	 */
	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	/**
	 * @param cost the cost to set
	 */
	public void setCost(String cost) {
		this.cost = cost;
	}

	/**
	 * @param delivertolerance the delivertolerance to set
	 */
	public void setDelivertolerance(String delivertolerance) {
		this.delivertolerance = delivertolerance;
	}

	/**
	 * @param delSelectedCategory the delSelectedCategory to set
	 */
	public void setDelSelectedCategory(String[] delSelectedCategory) {
		this.delSelectedCategory = delSelectedCategory;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @param details the details to set
	 */
	public void setDetails(String details) {
		this.details = details;
	}

	public void setEditbrand(String editbrand) {
		this.editbrand = editbrand;
	}

	/**
	 * @param editDeliverGeoRange the editDeliverGeoRange to set
	 */
	public void setEditDeliverGeoRange(String editDeliverGeoRange) {
		this.editDeliverGeoRange = editDeliverGeoRange;
	}

	public void setEditFlag(String editFlag) {
		this.editFlag = editFlag;
	}

	/**
	 * @param editleadtime the editleadtime to set
	 */
	public void setEditleadtime(String editleadtime) {
		this.editleadtime = editleadtime;
	}

	public void setEditProductCategories(List<ProductCategory> editProductCategories) {
		this.editProductCategories = editProductCategories;
	}

	/**
	 * @param editsupplier the editsupplier to set
	 */
	public void setEditsupplier(String editsupplier) {
		this.editsupplier = editsupplier;
	}

	public void setExpectShipDate(String expectShipDate) {
		this.expectShipDate = expectShipDate;
	}

	public void setFileMap(Map<String, String> fileMap) {
		this.fileMap = fileMap;
	}

	public void setFinalAddOnData(String finalAddOnData) {
		this.finalAddOnData = finalAddOnData;
	}

	public void setFlag01(String flag01) {
		this.flag01 = flag01;
	}

	public void setFlag02(String flag02) {
		this.flag02 = flag02;
	}

	public void setFlag03(String flag03) {
		this.flag03 = flag03;
	}

	public void setFlag04(String flag04) {
		this.flag04 = flag04;
	}

	public void setFlag05(String flag05) {
		this.flag05 = flag05;
	}

	public void setFlag06(String flag06) {
		this.flag06 = flag06;
	}

	public void setFlag07(String flag07) {
		this.flag07 = flag07;
	}

	public void setFlag08(String flag08) {
		this.flag08 = flag08;
	}

	public void setFlag09(String flag09) {
		this.flag09 = flag09;
	}

	public void setFlag10(String flag10) {
		this.flag10 = flag10;
	}

	public void setFlag11(String flag11) {
		this.flag11 = flag11;
	}

	public void setFlag12(String flag12) {
		this.flag12 = flag12;
	}

	public void setFlag13(String flag13) {
		this.flag13 = flag13;
	}

	public void setFlag14(String flag14) {
		this.flag14 = flag14;
	}

	public void setFlag15(String flag15) {
		this.flag15 = flag15;
	}

	public void setFlag16(String flag16) {
		this.flag16 = flag16;
	}

	public void setFreightMenu(Menu freightMenu) {
		this.freightMenu = freightMenu;
	}

	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}

	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}

	/**
	 * @param height the height to set
	 */
	public void setHeight(String height) {
		this.height = height;
	}

	public void setIsPmGroup(String isPmGroup) {
		this.isPmGroup = isPmGroup;
	}

	public void setJsonAddonProdSpec(String jsonAddonProdSpec) {
		this.jsonAddonProdSpec = jsonAddonProdSpec;
	}

	public void setJsonCategoryPath(String jsonCategoryPath) {
		this.jsonCategoryPath = jsonCategoryPath;
	}

	public void setJsonOrderNotice(String jsonOrderNotice) {
		this.jsonOrderNotice = jsonOrderNotice;
	}

	/**
	 * @param keyword the keyword to set
	 */
	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public void setLastMainCategoryId(String lastMainCategoryId) {
		this.lastMainCategoryId = lastMainCategoryId;
	}

	/**
	 * @param length the length to set
	 */
	public void setLength(String length) {
		this.length = length;
	}

	public void setMainCategory(Long mainCategory) {
		this.mainCategory = mainCategory;
	}

	public void setMainCategoryId(String mainCategoryId) {
		this.mainCategoryId = mainCategoryId;
	}

	/**
	 * @param mainCategoryName the mainCategoryName to set
	 */
	public void setMainCategoryName(String mainCategoryName) {
		this.mainCategoryName = mainCategoryName;
	}

	public void setMainCategoryText(String mainCategoryText) {
		this.mainCategoryText = mainCategoryText;
	}

	public void setMapRootCategories(Map<String, String> mapRootCategories) {
		this.mapRootCategories = mapRootCategories;
	}

	/**
	 * @param maxpo the maxpo to set
	 */
	public void setMaxpo(String maxpo) {
		this.maxpo = maxpo;
	}

	/**
	 * @param memo the memo to set
	 */
	public void setMemo(String memo) {
		this.memo = memo;
	}

	public void setMenuService(DomainService<Menu> menuService) {
		this.menuService = menuService;
	}

	/**
	 * @param minpo the minpo to set
	 */
	public void setMinpo(String minpo) {
		this.minpo = minpo;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	public void setOrderNotice(String orderNotice) {
		this.orderNotice = orderNotice;
	}

	/**
	 * @param organization the organization to set
	 */
	public void setOrganization(String organization) {
		this.organization = organization;
	}

	/**
	 * @param pager the pager to set
	 */
	public void setPager(SimplePager pager) {
		this.pager = pager;
	}

	/**
	 * @param pm the pm to set
	 */
	public void setPm(String pm) {
		this.pm = pm;
	}

	public void setPmIdParam(String pmIdParam) {
		this.pmIdParam = pmIdParam;
	}

	/**
	 * @param prdtDelete the prdtDelete to set
	 */
	public void setPrdtDelete(String[] prdtDelete) {
		this.prdtDelete = prdtDelete;
	}

	/**
	 * @param price the price to set
	 */
	public void setPrice(String price) {
		this.price = price;
	}

	/**
	 * @param product the product to set
	 */
	public void setProduct(Product product) {
		this.product = product;
	}

	public void setProductAttribute(String productAttribute) {
		this.productAttribute = productAttribute;
	}

	public void setProductAttributeParam(String productAttributeParam) {
		this.productAttributeParam = productAttributeParam;
	}

	public void setProductCategories(List<ProductCategory> productCategories) {
		this.productCategories = productCategories;
	}

	public void setProductCategoryMap(Map<Long, String> productCategoryMap) {
		this.productCategoryMap = productCategoryMap;
	}

	/**
	 * @param productId the productId to set
	 */
	public void setProductId(String productId) {
		this.productId = productId;
	}

	/**
	 * @param productIdParam the productIdParam to set
	 */
	public void setProductIdParam(String productIdParam) {
		this.productIdParam = productIdParam;
	}

	/**
	 * @param productNameParam the productNameParam to set
	 */
	public void setProductNameParam(String productNameParam) {
		this.productNameParam = productNameParam;
	}

	public void setProductPromotionFlag(ProductPromotionFlag productPromotionFlag) {
		this.productPromotionFlag = productPromotionFlag;
	}

	/**
	 * @param products the products to set
	 */
	public void setProducts(List<Product> products) {
		this.products = products;
	}

	/**
	 * @param productService the productService to set
	 */
	public void setProductService(ProductService productService) {
		this.productService = productService;
	}

	public void setProductStParam(String productStParam) {
		this.productStParam = productStParam;
	}

	public void setProductTypeParam(String productTypeParam) {
		this.productTypeParam = productTypeParam;
	}

	/**
	 * @param returnable the returnable to set
	 */
	public void setReturnable(String returnable) {
		this.returnable = returnable;
	}

	/**
	 * @param returnpickup the returnpickup to set
	 */
	public void setReturnpickup(String returnpickup) {
		this.returnpickup = returnpickup;
	}

	public void setRootCategories(List<Category> rootCategories) {
		this.rootCategories = rootCategories;
	}

	/**
	 * @param rsmap the rsmap to set
	 */
	public void setRsmap(Map<String, String> rsmap) {
		this.rsmap = rsmap;
	}

	/**
	 * @param selectedcategories the selectedcategories to set
	 */
	public void setSelectedcategories(List<ProductCategory> selectedcategories) {
		this.selectedcategories = selectedcategories;
	}

	/**
	 * @param setMainCategory the setMainCategory to set
	 */
	public void setSetMainCategory(String setMainCategory) {
		this.setMainCategory = setMainCategory;
	}

	public void setSetMainSupplier(String setMainSupplier) {
		this.setMainSupplier = setMainSupplier;
	}

	/**
	 * @param showSelectedCategory the showSelectedCategory to set
	 */
	public void setShowSelectedCategory(String showSelectedCategory) {
		this.showSelectedCategory = showSelectedCategory;
	}

	public void setShowSeq(String showSeq) {
		this.showSeq = showSeq;
	}

	public void setShowSpecSeq(String[] showSpecSeq) {
		this.showSpecSeq = showSpecSeq;
	}

	/**
	 * @param spcBarCode the spcBarCode to set
	 */
	public void setSpcBarCode(String[] spcBarCode) {
		this.spcBarCode = spcBarCode;
	}

	/**
	 * @param spcCode the spcCode to set
	 */
	public void setSpcCode(String[] spcCode) {
		this.spcCode = spcCode;
	}

	/**
	 * @param spcDelete the spcDelete to set
	 */
	public void setSpcDelete(String[] spcDelete) {
		this.spcDelete = spcDelete;
	}

	public void setSpcHotSaleInventory(String[] spcHotSaleInventory) {
		this.spcHotSaleInventory = spcHotSaleInventory;
	}

	/**
	 * @param spcId the spcId to set
	 */
	public void setSpcId(String[] spcId) {
		this.spcId = spcId;
	}

	/**
	 * @param spcMaxCountPerOrder the spcMaxCountPerOrder to set
	 */
	public void setSpcMaxCountPerOrder(String[] spcMaxCountPerOrder) {
		this.spcMaxCountPerOrder = spcMaxCountPerOrder;
	}

	/**
	 * @param spcMinCountPerOrder the spcMinCountPerOrder to set
	 */
	public void setSpcMinCountPerOrder(String[] spcMinCountPerOrder) {
		this.spcMinCountPerOrder = spcMinCountPerOrder;
	}

	/**
	 * @param spcName the spcName to set
	 */
	public void setSpcName(String[] spcName) {
		this.spcName = spcName;
	}

	/**
	 * @param spcReverseInventory the spcReverseInventory to set
	 */
	public void setSpcReverseInventory(String[] spcReverseInventory) {
		this.spcReverseInventory = spcReverseInventory;
	}

	/**
	 * @param spcSafeInventory the spcSafeInventory to set
	 */
	public void setSpcSafeInventory(String[] spcSafeInventory) {
		this.spcSafeInventory = spcSafeInventory;
	}

	/**
	 * @param specification the specification to set
	 */
	public void setSpecification(Specification specification) {
		this.specification = specification;
	}

	/**
	 * @param specificationinventory the specificationinventory to set
	 */
	public void setSpecificationinventory(SpecificationInventory specificationinventory) {
		this.specificationinventory = specificationinventory;
	}

	public void setSpecificationinventoryMap(Map<Long, List<Integer>> specificationinventoryMap) {
		this.specificationinventoryMap = specificationinventoryMap;
	}

	/**
	 * @param specificationinventorys the specificationinventorys to set
	 */
	public void setSpecificationinventorys(List<SpecificationInventory> specificationinventorys) {
		this.specificationinventorys = specificationinventorys;
	}

	/**
	 * @param specifications the specifications to set
	 */
	public void setSpecifications(List<Specification> specifications) {
		this.specifications = specifications;
	}

	public void setSpecStatus(String[] specStatus) {
		this.specStatus = specStatus;
	}

	public void setSpecStatusMenu(Menu specStatusMenu) {
		this.specStatusMenu = specStatusMenu;
	}

	public void setSpecStatusParam(String specStatusParam) {
		this.specStatusParam = specStatusParam;
	}

	public void setSpecSubStatusMenu(Menu specSubStatusMenu) {
		this.specSubStatusMenu = specSubStatusMenu;
	}

	public void setStockReports(List<Object> stockReports) {
		this.stockReports = stockReports;
	}

	public void setSupplierApplyService(SupplierApplyService supplierApplyService) {
		this.supplierApplyService = supplierApplyService;
	}

	public void setSupplierCompanyName(String supplierCompanyName) {
		this.supplierCompanyName = supplierCompanyName;
	}

	/**
	 * @param supplierDelete the supplierDelete to set
	 */
	public void setSupplierDelete(String[] supplierDelete) {
		this.supplierDelete = supplierDelete;
	}

	public void setSupplierParam(String supplierParam) {
		this.supplierParam = supplierParam;
	}

	/**
	 * @param suppliers the suppliers to set
	 */
	public void setSuppliers(Collection<SupplierApply> suppliers) {
		this.suppliers = suppliers;
	}

	/**
	 * @param tax the tax to set
	 */
	public void setTax(String tax) {
		this.tax = tax;
	}

	/**
	 * @param temperature the temperature to set
	 */
	public void setTemperature(String temperature) {
		this.temperature = temperature;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @param unit the unit to set
	 */
	public void setUnit(String unit) {
		this.unit = unit;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	/**
	 * @param virtual the virtual to set
	 */
	public void setVirtual(String virtual) {
		this.virtual = virtual;
	}

	/**
	 * @param volume the volume to set
	 */
	public void setVolume(String volume) {
		this.volume = volume;

	}

	/**
	 * @param weight the weight to set
	 */
	public void setWeight(String weight) {
		this.weight = weight;
	}

	/**
	 * @param width the width to set
	 */
	public void setWidth(String width) {
		this.width = width;
	}

	/* 編輯商品Spec */
	public String spec() throws Exception {
		if (StringUtils.isBlank(productId) || StringUtils.length(productId) != 8 || !NumberUtils.isNumber(productId)) {
			addActionError("传入参数错误");
			return list();
		} else {
			product = productService.get(productId);
			if (null == product) {
				addActionError("查无商品资料(或无该权限查看)");
				return list();
			}
			CommonCriteria crit = new CommonCriteria();
			crit.addEq("productId", productId);
			if (StringUtils.isBlank(specStatusParam)) {
				specStatusParam = "A";
			}
			if (!StringUtils.equalsIgnoreCase("A", specStatusParam)) {
				crit.addEq("isDelete", specStatusParam);
			}
			String[] sortOrder = new String[] { "showSeq asc", "modifyDate desc" };
			specifications = productService.getSpecificationList(0, -1, crit, sortOrder);

			for (Specification spec : specifications) {
				totalHotSale = totalHotSale + spec.getHotSaleInventory();
			}
			crit = new CommonCriteria();
			crit.addEq("productId", productId);
			List<SpecificationInventory> specificationInventories = productService.getSpecificationInventory(crit);
			List<Integer> nums = null;
			for (SpecificationInventory specificationInventory : specificationInventories) {
				nums = new ArrayList<Integer>();
				nums.add(0, specificationInventory.getAvailableInventory());
				nums.add(1, specificationInventory.getSoldInventory());
				nums.add(2, specificationInventory.getCancelInventory());
				specificationinventoryMap.put(specificationInventory.getSpecId(), nums);
				totalInventory = totalInventory + specificationInventory.getSoldInventory();
			}
			product = productService.get(productId);
			stockQty = productService.getStockOutByProductId(productId);
			return "spec";
		}
	}

	/**
	 * 缺货报表
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String stockOutReport() throws CoreException {
		return "stockOutReport";
	}

	/**
	 * 缺货报表
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String stockOutReportSearch() throws CoreException {
		User user = AdminHelper.getUser();
		if (user.getGroup().getCode().indexOf("A-20") < 0) {
			isPmGroup = "N";
		} else {
			isPmGroup = "Y";
		}
		if (isPmGroup.equals("Y")) {
			if (StringUtils.isBlank(categoryIdParam) && StringUtils.isBlank(productStParam) && StringUtils.isBlank(pmIdParam)) {
				addActionError("产品部门必须要输入其中一个条件");
			} else {
				stockReports = productService.getStockOutReport(Long
						.parseLong(StringUtils.isNotBlank(categoryIdParam) ? categoryIdParam : "0"), productStParam, pmIdParam,
						productIdParam, productNameParam, supplierParam, stockNotify, startStockQty, endStockQty);
			}
		} else {
			stockReports = productService.getStockOutReport(Long
					.parseLong(StringUtils.isNotBlank(categoryIdParam) ? categoryIdParam : "0"), productStParam, pmIdParam,
					productIdParam, productNameParam, supplierParam, stockNotify, startStockQty, endStockQty);
		}

		return "stockOutReport";
	}

	/**
	 * 缺货报表编辑预计到货日
	 * 
	 * @return
	 * @throws CoreException
	 * @throws ParseException
	 */
	public String stockOutReportSave() throws CoreException, ParseException {
		if (!ArrayUtils.isEmpty(productIdBoxs)) {
			for (String productId : productIdBoxs) {
				product = productService.get(productId);
				product.setArrivalDate(format.parse(arrivalDate));
				productService.update(product);
			}
		}
		return stockOutReportSearch();

	}

	// 已销售未出货的库存查询
	public String orderNotShipping() throws Exception {
		product = productService.get(productId);
		orderNoShippingList = productService.orderNotShipping(productId, specificId);
		if (orderNoShippingList.size() > 0) {
			specificationinventory = productService.getSpecificationInventory(productId, Long.parseLong(specificId));
		} else {
			specificationinventory = null;
		}
		specification = productService.getSpecification(Long.parseLong(specificId));
		return "orderNotShipping";

	}

	public String updateArrivalDate() throws Exception {
		if (StringUtils.isNotBlank(arrivalDate)) {
			product = productService.get(productId);
			product.setArrivalDate(format.parse(arrivalDate));
			productService.update(product);
		}
		return spec();
	}

	/* 上傳商品圖片 */
	public String upload() throws Exception {
		return "upload";
	}

	public String getIsScm() {
		return isScm;
	}

	public void setIsScm(String isScm) {
		this.isScm = isScm;
	}

	public String getScmNotice() {
		return scmNotice;
	}

	public void setScmNotice(String scmNotice) {
		this.scmNotice = scmNotice;
	}

	public ProductSupplierApproveService getProductSupplierApproveService() {
		return productSupplierApproveService;
	}

	public void setProductSupplierApproveService(ProductSupplierApproveService productSupplierApproveService) {
		this.productSupplierApproveService = productSupplierApproveService;
	}

	public String getHr24Result() {
		return hr24Result;
	}

	public void setHr24Result(String hr24Result) {
		this.hr24Result = hr24Result;
	}

	public Menu getExpireManageMenu() {
		return expireManageMenu;
	}

	public void setExpireManageMenu(Menu expireManageMenu) {
		this.expireManageMenu = expireManageMenu;
	}

	public String getExpireManage() {
		return expireManage;
	}

	public void setExpireManage(String expireManage) {
		this.expireManage = expireManage;
	}

	public SupplierApply getSp() {
		return sp;
	}

	public void setSp(SupplierApply sp) {
		this.sp = sp;
	}

	public String getSpResult() {
		return spResult;
	}

	public void setSpResult(String spResult) {
		this.spResult = spResult;
	}

	public String getIsAntiUnpacking() {
		return isAntiUnpacking;
	}

	public void setIsAntiUnpacking(String isAntiUnpacking) {
		this.isAntiUnpacking = isAntiUnpacking;
	}

	public List<AddOnProduct> getAddons() {
		return addons;
	}

	public void setAddons(List<AddOnProduct> addons) {
		this.addons = addons;
	}

	public List<AddOnProduct> getNms() {
		return nms;
	}

	public void setNms(List<AddOnProduct> nms) {
		this.nms = nms;
	}

	public int getApproveSize() {
		return approveSize;
	}

	public void setApproveSize(int approveSize) {
		this.approveSize = approveSize;
	}

	public List<AddOnProduct> getAddonsMain() {
		return addonsMain;
	}

	public void setAddonsMain(List<AddOnProduct> addonsMain) {
		this.addonsMain = addonsMain;
	}

	public boolean isChkHasInventory() {
		return chkHasInventory;
	}

	public void setChkHasInventory(boolean chkHasInventory) {
		this.chkHasInventory = chkHasInventory;
	}

	public String getGraphicType() {
		return graphicType;
	}

	public void setGraphicType(String graphicType) {
		this.graphicType = graphicType;
	}

	public String getPrpsShelfPrice() {
		return prpsShelfPrice;
	}

	public void setPrpsShelfPrice(String prpsShelfPrice) {
		this.prpsShelfPrice = prpsShelfPrice;
	}

	public String getCopy() {
		return copy;
	}

	public void setCopy(String copy) {
		this.copy = copy;
	}

	public boolean isStockNotify() {
		return stockNotify;
	}

	public void setStockNotify(boolean stockNotify) {
		this.stockNotify = stockNotify;
	}

	public int getStartStockQty() {
		return startStockQty;
	}

	public int getEndStockQty() {
		return endStockQty;
	}

	public void setStartStockQty(int startStockQty) {
		this.startStockQty = startStockQty;
	}

	public void setEndStockQty(int endStockQty) {
		this.endStockQty = endStockQty;
	}

	public String[] getProductIdBoxs() {
		return productIdBoxs;
	}

	public void setProductIdBoxs(String[] productIdBoxs) {
		this.productIdBoxs = productIdBoxs;
	}

	public String getArrivalDate() {
		return arrivalDate;
	}

	public void setArrivalDate(String arrivalDate) {
		this.arrivalDate = arrivalDate;
	}

	public int getStockQty() {
		return stockQty;
	}

	public void setStockQty(int stockQty) {
		this.stockQty = stockQty;
	}

	public int getTotalInventory() {
		return totalInventory;
	}

	public void setTotalInventory(int totalInventory) {
		this.totalInventory = totalInventory;
	}

	public int getTotalHotSale() {
		return totalHotSale;
	}

	public void setTotalHotSale(int totalHotSale) {
		this.totalHotSale = totalHotSale;
	}

	public String getIsValidateNum() {
		return isValidateNum;
	}

	public void setIsValidateNum(String isValidateNum) {
		this.isValidateNum = isValidateNum;
	}

	public String getUseDeliveryDay() {
		return useDeliveryDay;
	}

	public int getDeliveryDay() {
		return deliveryDay;
	}

	public void setUseDeliveryDay(String useDeliveryDay) {
		this.useDeliveryDay = useDeliveryDay;
	}

	public void setDeliveryDay(int deliveryDay) {
		this.deliveryDay = deliveryDay;
	}

	public String getUserPermissions() {
		return userPermissions;
	}

	public void setUserPermissions(String userPermissions) {
		this.userPermissions = userPermissions;
	}

	public String getEditTwSupplier() {
		return editTwSupplier;
	}

	public void setEditTwSupplier(String editTwSupplier) {
		this.editTwSupplier = editTwSupplier;
	}

	public String getTwSupplierCompanyName() {
		return twSupplierCompanyName;
	}

	public void setTwSupplierCompanyName(String twSupplierCompanyName) {
		this.twSupplierCompanyName = twSupplierCompanyName;
	}

	public String getScmParam() {
		return scmParam;
	}

	public void setScmParam(String scmParam) {
		this.scmParam = scmParam;
	}

	public String getSpecificId() {
		return specificId;
	}

	public void setSpecificId(String specificId) {
		this.specificId = specificId;
	}

	public List<Object> getOrderNoShippingList() {
		return orderNoShippingList;
	}

	public void setOrderNoShippingList(List<Object> orderNoShippingList) {
		this.orderNoShippingList = orderNoShippingList;
	}

	public Menu getOrderStMenu() {
		return orderStMenu;
	}

	public void setOrderStMenu(Menu orderStMenu) {
		this.orderStMenu = orderStMenu;
	}
}